package com.dashu.core.controller;

import com.dashu.core.result.PageEnty;
import com.dashu.core.result.ResultBean;
import com.dashu.core.dto.JurisdictionDTO;
import com.dashu.core.service.JurisdictionService;
import com.dashu.core.vo.JurisdictionVO;
import com.dashu.core.vo.UpdateEntityVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @Author xys
 * @Date 2020/11/17 15:21
 */

@RequestMapping("dashu/jurisdiction")
@RestController
@Slf4j
@Api(value = "dashu/jurisdiction", tags = {"管控权限模块"}, description = "后台")
public class JurisdictionController {

    @Autowired
    private JurisdictionService jurisdictionService;
//    @Autowired
//    RestTemplate restTemplate;

    @PostMapping("/addJurisdiction")
    @ApiOperation(value = "管控添加", notes = "管控添加")
    public ResultBean<JurisdictionDTO> addJurisdiction(@RequestBody @Validated JurisdictionVO jurisdictionVO) {
        return new ResultBean<>(1, "管控添加", jurisdictionService.add(jurisdictionVO));
    }

    @PostMapping("/updataJurisdiction")
    @ApiOperation(value = "管控信息修改", notes = "管控信息修改")
    public ResultBean<JurisdictionDTO> updataJurisdiction(@RequestBody @Validated UpdateEntityVO<JurisdictionVO> updateEntityVO) {
        return new ResultBean<>(1, "管控信息修改", jurisdictionService.updataByJurisdictionRuleId(updateEntityVO));

    }

    @GetMapping("/findBase")
    @ApiOperation(value = "父节点查询管控列表", notes = "父节点查询管控列表")
    public ResultBean<List<JurisdictionDTO>> findBase(@RequestBody @Validated PageEnty<Long> basrVo) {
        return new ResultBean<>(1, "父节点查询管控列表", jurisdictionService.findByBaseId(basrVo));

    }
    @GetMapping("/findJurisdiction")
    @ApiOperation(value = "管控信息查询", notes = "管控信息查询")
    public ResultBean<JurisdictionDTO> findJurisdiction(@RequestBody @Validated long findJurisdictionId) {
        return new ResultBean<>(1, "管控信息查询", jurisdictionService.findByJurisdictionRuleId(findJurisdictionId));

    }

    @DeleteMapping("/deleteJurisdiction")
    @ApiOperation(value = "管控信息删除", notes = "管控信息删除")
    public ResultBean<JurisdictionDTO> deleteJurisdiction(@RequestBody @Validated long findJurisdictionId) {
        return new ResultBean<>(1, "管控信息删除", jurisdictionService.findByJurisdictionRuleId(findJurisdictionId));

    }

}
